package com.example.cors.controller;


import com.example.cors.domain.CorsReq;
import com.example.cors.service.CorsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@CrossOrigin(origins = "*")
public class CorsController{

    @Autowired
    CorsService corsService;

    @PostMapping("/cors")
    public String corsPost(@RequestBody CorsReq body, HttpServletRequest req) throws IOException {
        body.setReq(req);
        return corsService.sendReq(body);
    }

}
